#pragma once
#include "Observer.h"
#include "ClockTimer.h"

class DigitalClock : public Observer
{
public:
	DigitalClock(ClockTimer*);
	virtual ~DigitalClock();

	virtual void Update(Subject*);

	virtual void Draw();

private:
	ClockTimer* subject_;
	HANDLE style_;
};

DigitalClock::DigitalClock(ClockTimer* s)
	: Observer()
{
	subject_ = s;
	subject_->Attach(this);
	style_ = GetStdHandle(STD_OUTPUT_HANDLE);
}

DigitalClock::~DigitalClock()
{
	subject_->Detach(this);
}

void DigitalClock::Update(Subject* theChangedSubject)
{
	if (theChangedSubject == subject_) {
		Draw();
	}
}

void DigitalClock::Draw()
{
	int hour = subject_->GetHour();
	int minute = subject_->GetMinute();
	int sec = subject_->GetSecond();
	// draw the digital clock.
	SetConsoleTextAttribute(style_, FOREGROUND_INTENSITY | FOREGROUND_BLUE);
	cout << "Digital: " << hour << ":" << minute << ":" << sec << endl;	
}
